package com.yu.Controller;

import com.yu.POJO.Clazz;
import com.yu.POJO.Course;
import com.yu.POJO.Sc;
import com.yu.POJO.Student;
import com.yu.Service.teaService;
import com.yu.tool.MyJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: LittleFisher
 * @Date: 2021/06/10/0:40
 * @Description:
 */
@Controller
@RequestMapping("tea")
public class teaController {
    @Autowired
    private teaService teaService;

//to

    /**
     * 去获取老师所教课程的页面
     * @return
     */
    @RequestMapping("/toTeaCourse")
    public String toTeaCourse(){
        return "tea/teaCourse";
    }

    /**
     * 去老师更改密码页面
     * @return
     */
    @RequestMapping("/toUpdateTeaPassword")
    public String toUpdateTeaPassword(){
        return "tea/updatePassword";
    }

    /**
     * 去老师录入成绩
     * @return
     */
    @RequestMapping("/toUpGrade")
    public String toUpGrade(){
        return "tea/upGrade";
    }

    @RequestMapping("/toTeaClazz")
    public String toTeaClazz(){
        return "tea/teaClazz";
    }

    /**
     * 获取老师(id)所教的课程
     * @param id 老师id
     * @return
     */
    @RequestMapping("teaGetCourse")
    @ResponseBody
    public List<Course> teaGetCourse(int id){
        return teaService.teaGetCourse(id);
    }

    /**
     *
     * @param id 老师id
     * @param old 旧密码
     * @param newp 新密码
     * @return MyJson msg 成功失败 error 错误信息
     */
    @RequestMapping(value = "/teaUpPass")
    @ResponseBody
    public MyJson teaUpPass(int id, String old, String newp){
        return teaService.upPass(id,old,newp);
    }

    /**
     *  录入成绩
     * @param id sc表id
     * @param grade 分数
     * @return
     */
    @RequestMapping(value = "/teaUpGrade")
    @ResponseBody
    public MyJson teaUpGrade(int id, double grade){
        Sc sc = new Sc();
        sc.setId(id);
        sc.setGrade(grade);
        return teaService.upGrade(sc);
    }

    @RequestMapping("/getTeaSC")
    @ResponseBody
    public List<Sc> getTeaSC(int course_id){
        return teaService.getTeaSC(course_id);
    }

    @RequestMapping("/getTeaClazzName")
    @ResponseBody
    public List<Clazz> getTeaClazzName(int tea_id){
        return teaService.teaClazzName(tea_id);
    }

    @RequestMapping("/getTeaClazzStu")
    @ResponseBody
    public List<Student> getTeaClazzStu(int clazz_id){
        return teaService.getClazzStu(clazz_id);
    }
}
